#!/bin/sh

# stage1 need this
mkdir -p /image

# setup stage2 as init
mv -f /usr/sbin/install2-init /sbin/init

# remove all docs
rm -rf /usr/share/{doc,man,info,license,gfxboot}

# remove icons
rm -rf /usr/share/icons/{hicolor,large,mini}

# remove PAM plugins
rm -rf /lib*/security

# remove cpp
rpmquery -a cpp\* gcc\* |
	xargs -r rpmi -e --nodeps --

# remove X11 dri modules
rm -rf /usr/lib*/X11/modules/dri
rm -rf /usr/lib*/X11/modules/multimedia
rm -rf /usr/lib*/X11/mesa_gl

rm -f /usr/lib*/X11/modules/extensions/libglx.so
rm -f /usr/lib*/X11/modules/extensions/libdri.so
rm -f /usr/lib*/X11/modules/extensions/libGLcore.so

# remove unneeded kernel modules
rm -rf /lib/modules/*/kernel/arch
rm -rf /lib/modules/*/kernel/crypto
rm -rf /lib/modules/*/kernel/drivers/atm
rm -rf /lib/modules/*/kernel/drivers/char/watchdog
rm -rf /lib/modules/*/kernel/drivers/cpufreq
rm -rf /lib/modules/*/kernel/drivers/edac
rm -rf /lib/modules/*/kernel/drivers/firmware
rm -rf /lib/modules/*/kernel/drivers/hwmon
rm -rf /lib/modules/*/kernel/drivers/infiniband
rm -rf /lib/modules/*/kernel/drivers/input/{gameport,joy*}
rm -rf /lib/modules/*/kernel/drivers/isdn
rm -rf /lib/modules/*/kernel/drivers/media
rm -rf /lib/modules/*/kernel/drivers/mmc
rm -rf /lib/modules/*/kernel/drivers/mtd*
rm -rf /lib/modules/*/kernel/drivers/net/irda
rm -rf /lib/modules/*/kernel/drivers/rtc
rm -rf /lib/modules/*/kernel/drivers/spi
rm -rf /lib/modules/*/kernel/drivers/telephony
rm -rf /lib/modules/*/kernel/drivers/usb/{misc,mon}
rm -rf /lib/modules/*/kernel/drivers/video
rm -rf /lib/modules/*/kernel/drivers/bluetooth
rm -rf /lib/modules/*/kernel/drivers/ieee1394
rm -rf /lib/modules/*/kernel/drivers/w1
rm -rf /lib/modules/*/kernel/fs/quota*
rm -rf /lib/modules/*/kernel/fs/9p
rm -rf /lib/modules/*/kernel/fs/adfs
rm -rf /lib/modules/*/kernel/fs/affs
rm -rf /lib/modules/*/kernel/fs/afs
rm -rf /lib/modules/*/kernel/fs/autofs
rm -rf /lib/modules/*/kernel/fs/autofs4
rm -rf /lib/modules/*/kernel/fs/befs
rm -rf /lib/modules/*/kernel/fs/bfs
rm -rf /lib/modules/*/kernel/fs/cifs
rm -rf /lib/modules/*/kernel/fs/coda
rm -rf /lib/modules/*/kernel/fs/configfs
rm -rf /lib/modules/*/kernel/fs/cramfs
rm -rf /lib/modules/*/kernel/fs/efs
rm -rf /lib/modules/*/kernel/fs/exportfs
rm -rf /lib/modules/*/kernel/fs/freevxfs
rm -rf /lib/modules/*/kernel/fs/fuse
rm -rf /lib/modules/*/kernel/fs/hfs
rm -rf /lib/modules/*/kernel/fs/hfsplus
rm -rf /lib/modules/*/kernel/fs/hpfs
rm -rf /lib/modules/*/kernel/fs/jffs
rm -rf /lib/modules/*/kernel/fs/jffs2
rm -rf /lib/modules/*/kernel/fs/lockd
rm -rf /lib/modules/*/kernel/fs/minix
rm -rf /lib/modules/*/kernel/fs/ncpfs
rm -rf /lib/modules/*/kernel/fs/ocfs2
rm -rf /lib/modules/*/kernel/fs/qnx4
rm -rf /lib/modules/*/kernel/fs/smbfs
rm -rf /lib/modules/*/kernel/fs/sysv
rm -rf /lib/modules/*/kernel/fs/udf
rm -rf /lib/modules/*/kernel/fs/ufs
rm -rf /lib/modules/*/kernel/fs/ecryptfs
rm -rf /lib/modules/*/kernel/net/*/netfilter
rm -rf /lib/modules/*/kernel/net/appletalk
rm -rf /lib/modules/*/kernel/net/ax25
rm -rf /lib/modules/*/kernel/net/bluetooth
rm -rf /lib/modules/*/kernel/net/bridge
rm -rf /lib/modules/*/kernel/net/dccp
rm -rf /lib/modules/*/kernel/net/decnet
rm -rf /lib/modules/*/kernel/net/econet
rm -rf /lib/modules/*/kernel/net/ipv6
rm -rf /lib/modules/*/kernel/net/ipx
rm -rf /lib/modules/*/kernel/net/irda
rm -rf /lib/modules/*/kernel/net/netfilter
rm -rf /lib/modules/*/kernel/net/netrom
rm -rf /lib/modules/*/kernel/net/rose
rm -rf /lib/modules/*/kernel/net/sctp
rm -rf /lib/modules/*/kernel/net/tipc
rm -rf /lib/modules/*/kernel/net/x25
rm -rf /lib/modules/*/kernel/sound

# remove blacklisted kernel modules
sed -n 's/^blacklist[[:space:]]\+\([^[:space:]]\+\).*/\1/p' /etc/modprobe.d/* |
	while read i; do
		/.host/find /lib/modules/ -type f -name "$i.ko" -delete
	done

# remove rpm db
rm -rf /var/lib/rpm/*

# remove apt data files
rm -rf /var/cache/apt /var/lib*/apt

# remove unneeded translations
/.host/find /usr/share/locale/ -type f \! -name 'alterator*' -delete

# remove non-utf8 locales
/.host/find /usr/lib*/locale -mindepth 1 -maxdepth 1 -type d \! -name '*.utf8' -print0 |
	xargs -r0 rm -rf --

# udev needed this 
ln -sf /proc/mounts /etc/mtab


# run depmod
for i in /lib*/modules/*; do
    /sbin/depmod -a -F /boot/System.map-${i##*/} ${i##*/}
done

# remove ogfs
rm -f /lib*/evms/*/ogfs*

# remove kernel images
rm -rf /boot/*

# remove unneeded pixmaps
rm -f /usr/share/pixmapsv/xterm*

#remove desktop files
rm -f /usr/share/applications/*

#remove X11 locales
rm -Rf /usr/share/X11/locale/ja*
rm -Rf /usr/share/X11/locale/ko*
rm -Rf /usr/share/X11/locale/zh*
rm -Rf /usr/share/X11/locale/vi*

# remove /usr/local
rm -Rf /usr/local/*

# remove all headers
rm -Rf /usr/include/*

# clean files in /sbin
rm -f /sbin/udevconvertdb
rm -f /sbin/tcb_*
rm -f /sbin/installinfo
rm -f /sbin/installkernel
rm -f /sbin/glibc_*


#remove in /lib
rm -fR /lib/mkinitrd

#remove skel 
rm -fR /etc/skel*

#cleanup /etc
rm -Rf /etc/firsttime.d
rm -Rf /etc/buildreqs
rm -Rf /etc/info-dir


#/bin
rm -f /bin/ipv6calc

# remove console-kit-daemon
#rm -f /usr/share/dbus-1/system-services/*
#rm -rf /usr/share/PolicyKit
#rm -f /usr/sbin/ck-*
#rm -f /usr/sbin/console-kit-*
#rm -rf /usr/libexec/ConsoleKit
#rm -rf /usr/libexec/PolicyKit

